package com.company.ThreadDemo;

public class Ticket implements Runnable{
    private static  int num = 15;
    private String name;

    @Override
    public void run() {
        while(true){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(num<=0){
                break;
            }
            System.out.println(Thread.currentThread().getName()+"获取了"+num--+"张票");
        }
    }
    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        new Thread(ticket,"张三").start();
        new Thread(ticket,"李四").start();
        new Thread(ticket,"王五").start();

        //李四获取了14张票
        //王五获取了15张票
        //张三获取了13张票
        //张三获取了12张票
        //王五获取了11张票
        //李四获取了12张票
        //王五获取了10张票
        //张三获取了9张票
        //李四获取了9张票
        //李四获取了8张票
        //张三获取了6张票
        //王五获取了7张票
        //李四获取了5张票
        //王五获取了4张票
        //张三获取了3张票
        //王五获取了2张票
        //张三获取了1张票
        //李四获取了2张票
        //
        //Process finished with exit code 0
    }


}
